
find_package(PkgConfig REQUIRED)
pkg_check_modules(AVFORMAT REQUIRED libavformat)
pkg_check_modules(AVUTIL REQUIRED libavutil)
pkg_check_modules(VPX REQUIRED vpx)
pkg_check_modules(BRAEKPAD_CLIENT REQUIRED breakpad-client)

# add_definitions("-Wall -g")

option(OPTION_WITH_O1 "With -O1" OFF)
if(OPTION_WITH_O1)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fno-omit-frame-pointer")
endif()

add_subdirectory(../../src src)

include_directories(
        ${BRAEKPAD_CLIENT_INCLUDE_DIRS}
)


add_executable(rtc-xswitch ${RTC_XSWITCH_SOURCES} ${RTP_SOURCES} ${NMEDIA_SOURCES} main_rtc_xswitch.cpp expire_date.hpp)

add_custom_target(regenerate
        COMMAND echo "rm -f ${CMAKE_CURRENT_SOURCE_DIR}/expire_date.hpp"
        COMMAND rm -f ${CMAKE_CURRENT_SOURCE_DIR}/expire_date.hpp
        COMMAND ${CMAKE_COMMAND} -DEXPIRE_DATE_IN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/expire_date.hpp.in -DEXPIRE_DATE_OUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/expire_date.hpp -P "${CMAKE_CURRENT_LIST_DIR}/RegenerateExpireDate.cmake"
)

add_dependencies(rtc-xswitch regenerate)

# ffmpeg was used to output audio mixer debug data
# which is enabled by defining MIXER_DEBUG
# todo: make ffmpeg linked only for debug build

link_directories(
        ${AVFORMAT_LIBRARY_DIRS}
        ${AVCODEC_LIBRARY_DIRS}
        ${AVUTIL_LIBRARY_DIRS}
        ${VPX_LIBRARY_DIRS}
        ${BRAEKPAD_CLIENT_LIBRARY_DIRS}
        ${CMAKE_SOURCE_DIR}/stage/lib/
)

target_link_libraries(rtc-xswitch
        ${LOG4CPLUS_LDFLAGS}
	${GLIB_LDFLAGS}
        ${GOBJECT_LDFLAGS}
        ${GIO_LDFLAGS}
        ${OPENSSL_LDFLAGS}
        ${OPUS_LDFLAGS}
        ${LIBSOUP_LDFLAGS}
        ${SRTP_LDFLAGS}
        ${NICE_LDFLAGS}
        "-L${CMAKE_SOURCE_DIR}/third/webrtc/lib/ -laudio_recveq -lpthread"
        ${AVFORMAT_STATIC_LIBRARIES}
        ${AVCODEC_STATIC_LIBRARIES}
        ${AVUTIL_STATIC_LIBRARIES}
        ${VPX_STATIC_LIBRARIES}
        ${BRAEKPAD_CLIENT_STATIC_LIBRARIES}
        "-lmp3lame"
        "-ldl"
        )

if (APPLE)
    set_target_properties(rtc-xswitch PROPERTIES LINK_FLAGS "-framework CoreServices")
endif (APPLE)

if (LIBEXECINFO_STANDALONE)
    target_link_libraries(rtc-xswitch -lexecinfo)
endif(LIBEXECINFO_STANDALONE)

install(TARGETS rtc-xswitch DESTINATION bin)
install(FILES ../../log4cplus.properties DESTINATION conf)
